#include "GapStateUnregistered.h"
#include "GapStateMap.h"
#include "SgwGapProxy.h"
#include "Trace.h"

namespace tsc
{
namespace mgw
{

using namespace tsc::common;

/*******************************************************************************
 *
 * Constructor
 *
 ******************************************************************************/
GapStateUnregistered::GapStateUnregistered() :
	GapStateBase("Unregistered")
{

} // GapStateUnregistered::GapStateUnregistered

/*******************************************************************************
 *
 * Destructor
 *
 ******************************************************************************/
GapStateUnregistered::~GapStateUnregistered()
{

} // GapStateUnregistered::~GapStateUnregistered

//===================================================================
GapStateUnregistered* GapStateUnregistered::instance()
{
	static GapStateUnregistered mInstance;
	return &mInstance;
}

//===================================================================
void
GapStateUnregistered::handleEventGapT711Expired(
    GapGenerator* gapGen,
    GapEventT711Expired* event,
    EventData*& eventData)
{
    TRACE(3, "Trying to establish connection with SGW");

    if(SgwGapProxy::instance().sendGapConnectionInd(*gapGen))
    {
        gapGen->startT709();
        gapGen->changeState(GapStateMap::mpStateRegisterPend);
    }
    else
    {
        TRACE(1,
          STR("Sending GapConnectInd failed - will try again in %u[ms]",
              T_711_VALUE));

        gapGen->startT711();
    }

    EventData::deleteEvent(eventData);
}


} // namespace mgw
} // namespace tsc
